package com.test;

import com.test.entity.Order;
import com.test.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

/**
 * @author 韦存滨
 * @className UserController
 * @description
 * @date 2022年11月28日 23:29
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("{userId}")
    public User findById(@PathVariable String userId){
        String url = "http://localhost:10000/order/12";
        Order[] orders = restTemplate.getForObject(url, Order[].class);
        User user = new User(userId, "wei", Arrays.asList(orders.clone()));
        return user;
    }
}